﻿using CommunityToolkit.Mvvm.ComponentModel;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using XYAC.Framework.MonitorTireMaterialManual.DataExporter;
using XYAC.Framework.MonitorTireMaterialManual.OracleRemoteDB;

namespace XYAC.Framework.MonitorTireMaterialManual.Entities
{
    public partial class SemiSteelTriangleRubberReport : ReportEntityBase
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int ID { get; set; }
        public bool? IsDeleted { get; set; }
        [ObservableProperty]
        public string? _userId;

        /// <summary>
        /// 补偿系数
        /// </summary>
        [ObservableProperty]
        private double? _compensationCoefficient = 0.0;
        /// <summary>
        /// 条码号 SERIAL_NUMBER
        /// </summary>
        [ObservableProperty]
        [Description("条码号")]
        private string? _serialNumber;

        /// <summary>
        /// 扫描时间
        /// </summary>
        [ObservableProperty]
        [Description("扫描时间")]
        private string? _scanedDatetime;

        /// <summary>
        /// 规格号
        /// </summary>
        [ObservableProperty]
        [Description("规格号")]
        private string? _specName;

        /// <summary>
        /// 实际规格号
        /// </summary>
        [Description("实际规格号")]
        [ObservableProperty]
        private string? _specNameInfact;
        /// <summary>
        /// 总面积=左设定面积+右设定面积
        /// </summary>
        [Description("总面积")]
        [ObservableProperty]
        private double? _totalArea = 0.0;

        /// <summary>
        /// 总宽标准
        /// </summary>
        [Description("总宽标准")]
        [ObservableProperty]
        private double? _totalWidth_Stable = 0.0;

        /// <summary>
        /// 总宽扫描
        /// </summary>
        [Description("总宽扫描")]
        [ObservableProperty]
        private double? _totalWidth_Scan = 0.0;

        /// <summary>
        /// 三角胶厚度标准
        /// </summary>
        [Description("三角胶厚度标准")]
        [ObservableProperty]
        private double? _totalThickness_Stable = 0.0;

        /// <summary>
        /// 三角胶厚度标准扫描
        /// </summary>
        [Description("三角胶厚度标准扫描")]
        [ObservableProperty]
        private double? _totalThickness_Scan = 0.0;
        /// <summary>
        /// 端点厚度
        /// </summary>
        [Description("端点厚度")]
        [ObservableProperty]
        private double? _totalThickness_Points = 0.0;

        /// <summary>
        /// 拐点厚度标准
        /// </summary>
        [Description("拐点厚度标准")]
        [ObservableProperty]
        private double? _angleThickness_Stable = 0.0;
        /// <summary>
        /// 拐点厚度扫描
        /// </summary>
        [Description("拐点厚度扫描")]
        [ObservableProperty]
        private double? _angleThickness_Scan = 0.0;

        /// <summary>
        /// 拐点厚度标准
        /// </summary>
        [Description("拐点厚度标准")]
        [ObservableProperty]
        private double? _angleWidth_Stable = 0.0;
        /// <summary>
        /// 拐点厚度扫描
        /// </summary>
        [Description("拐点厚度扫描")]
        [ObservableProperty]
        private double? _angleWidth_Scan = 0.0;

        /// <summary>
        /// 机台编号
        /// </summary>
        [Description("机台编号")]
        [ObservableProperty]
        private string? _eqp;
        /// <summary>
        /// 最后同步时间
        /// </summary>
        [ObservableProperty]
        [Description("最后同步时间")]
        private DateTime? _lastSyncDate;
        /// <summary>
        /// 同步状态
        /// </summary>
        [ObservableProperty]
        [Description("同步状态")]
        private Boolean _syncState = false;
        /// <summary>
        /// 判定结果:是否合格 
        /// </summary>
        [ObservableProperty]
        [Description("是否合格")]
        private string? _passStatus = "True";

        /// <summary>
        /// 备注
        /// </summary>
        [ObservableProperty]
        [Description("备注")]
        private string? _remark;
        ///// <summary>
        ///// 班次
        ///// </summary>
        //[ObservableProperty]
        //public string _shift;
        /// <summary>
        /// 断面形状
        /// </summary>
        [Description("断面形状")]
        [ObservableProperty]
        private string? _crossSectionShape = "True";
        [ObservableProperty]
        [Description("左侧面积")]
        private double? _totalLeftArea = 0.0f;
        [ObservableProperty]
        [Description("右侧面积")]
        private double? _totalRightArea = 0.0f;
        [ObservableProperty]
        [Description("测量总面积")]

        private double? _measureArea = 0.0f;
        [ObservableProperty]
        [Description("左侧测量面积")]
        private double? _measureLeftArea = 0.0f;
        [ObservableProperty]
        [Description("右侧测量面积")]
        private double? _measureRightArea = 0.0f;

        /// <summary>
        /// 宽度(mm) 标准
        /// SemiSteelTriangleRubberReport.TotalWidth_Stable
        /// TXT文档，[Keys]下面最后一行的左边数字
        /// </summary>
        [ObservableProperty]
        [Description("宽度标准(mm)")]
        private double _data7;
        /// <summary>
        /// 宽度(mm) 实测
        /// TXT文档，[MeasureKeys]下面最后一行的左边数字
        /// SemiSteelTriangleRubberReport.TotalWidth_Scan
        /// </summary>
        [ObservableProperty]
        [Description("宽度实测(mm)")]
        private double _data9;

        /// <summary>
        /// 厚度(mm) 标准
        /// 分四种情况：
        /// 1、Keys行数=2
        /// TXT文档，[Keys]下面最后一行的右边数字
        /// 2、Keys行数=3并且[keys]最后一行右边等于0
        /// TXT文档，[Keys]下面倒数第二行的右边数字
        /// 3、Keys行数=3并且[keys]最后一行右边不等于0
        /// TXT文档，[Keys]下面最后一行的右边数字
        /// 4、Keys行数=4
        /// TXT文档，[Keys]下面倒数第二行的右边数字
        /// 
        /// SemiSteelTriangleRubberReport.TotalThickness_Stable
        /// </summary>
        [ObservableProperty]
        [Description("厚度标准(mm)")]
        private double _data10;
        /// <summary>
        /// 厚度(mm) 实测
        /// 分四种情况：
        /// 1、Keys行数=2
        /// TXT文档MeasureKeys下第二行右边数字(Keys行数=2的情况)
        /// TXT文档，[[MeasureKeys]下面倒数第二行的右边数字
        /// 2、Keys行数=3并且[keys]最后一行右边等于0
        /// TXT文档，[[MeasureKeys]下面倒数第二行的右边数字
        /// 3、Keys行数=3并且[keys]最后一行右边不等于0
        /// TXT文档，[[MeasureKeys]下面倒数第二行的右边数字（MesureKeys行数=4）
        /// TXT文档，[[MeasureKeys] 下面倒数第一行的右边数字（MesureKeys行数=3）
        /// 4、Keys行数=4
        /// TXT文档，[[MeasureKeys]下面倒数第二行的右边数字
        /// SemiSteelTriangleRubberReport.TotalThickness_Scan
        /// </summary>
        [ObservableProperty]
        [Description("厚度实测(mm)")]
        private double _data12;

        /// <summary>
        /// 端点厚度(mm) 实测
        /// TXT文档，[MeasureKeys]下面第一行的右边数字
        /// SemiSteelTriangleRubberReport.TotalThickness_Points
        /// </summary>
        [ObservableProperty]
        [Description("端点厚度实测(mm)")]
        private double _data15;


        /// <summary>
        /// 拐点厚度(mm) 标准
        /// 分四种情况：
        /// 1、Keys行数=2
        /// 无拐点，null
        /// 2、Keys行数=3并且[keys]最后一行右边等于0
        /// 无拐点，null
        /// 3、Keys行数=3并且[keys]最后一行右边不等于0
        /// TXT文档，[Keys]下面第二行的右边数字
        /// 4、Keys行数=4
        /// TXT文档，[Keys]下面第二行的右边数字
        /// SemiSteelTriangleRubberReport.AngleThickness_Stable
        /// </summary>
        [ObservableProperty]
        [Description("拐点厚度标准(mm)")]
        private double _data16;
        /// <summary>
        /// 拐点厚度(mm) 实测
        /// 分四种情况：
        /// 1、Keys行数=2
        /// 无拐点，null
        /// 2、Keys行数=3并且[keys]最后一行右边等于0
        /// 无拐点，null
        /// 3、Keys行数=3并且[keys]最后一行右边不等于0
        /// TXT文档，[MeasureKeys]下面第二行的右边数字
        /// 4、Keys行数=4
        /// TXT文档，[MeasureKeys]下面第二行的右边数字
        /// SemiSteelTriangleRubberReport.AngleThickness_Scan
        /// </summary>
        [ObservableProperty]
        [Description("拐点厚度实测(mm)")]
        private double _data18;

        /// <summary>
        /// 拐点宽度(mm) 标准
        /// TXT文档，[Keys]下面最后一行的左边数字-[Keys]下面第二行的左边数字
        /// SemiSteelTriangleRubberReport.AngleWidth_Stable
        /// </summary>
        [ObservableProperty]
        [Description("拐点宽度标准(mm)")]
        private double _data19;
        /// <summary>
        /// 拐点宽度(mm) 实测
        /// 分四种情况：
        /// 1、Keys行数=2
        /// 无拐点，null
        /// 2、Keys行数=3并且[keys]最后一行右边等于0
        /// 无拐点，null
        /// 3、Keys行数=3并且[keys]最后一行右边不等于0
        /// TXT文档，[Keys]下面最后一行的左边数字-TXT文档，[Keys]下面第二行的左边数字
        /// 4、Keys行数=4
        /// TXT文档，[Keys]下面最后一行的左边数字-TXT文档，[Keys]下面第二行的左边数字
        /// SemiSteelTriangleRubberReport.AngleWidth_Scan
        /// </summary>
        [ObservableProperty]
        [Description("拐点宽度实测(mm)")]
        private double _data21;


        /// <summary>
        /// 将 SemiSteelSideInspectionReport 实例转换为 YB_PROCESS_STEP 实例。
        /// </summary>
        /// <param name="report">要转换的 SemiSteelSideInspectionReport 实例。</param>
        /// <returns>转换后的 YB_PROCESS_STEP 实例。</returns>
        public override YB_PROCESS_STEP ToYB_PROCESS_STEP(DataFile dataFile)
        {
            //var dataFile = DataFile.FromSpecVal(this.SpecVal);

            var processStep = new YB_PROCESS_STEP
            {
                // 映射 SemiSteelSideInspectionReport 的字段到 RECORD16 至 RECORD32
                RECORD190 = this.CompensationCoefficient?.ToString("F2"),
                PLAN_ID = this.PlanId,
                PART_NUMBER = this.SpecName,

                //RECORD122 = this.TotalArea.ToString("F2"),
                //RECORD123 = this.MeasureArea.ToString("F2"),
                //RECORD124 = this.TotalLeftArea.ToString("F2"),
                //RECORD125 = this.MeasureLeftArea.ToString("F2"),
                //RECORD126 = this.TotalRightArea.ToString("F2"),
                //RECORD127 = this.MeasureRightArea.ToString("F2"),

                //总宽设定值
                RECORD128 = this.TotalWidth_Stable?.ToString("F2"),
                RECORD129 = this.TotalWidth_Scan?.ToString("F2"),

                ////左侧宽设定值
                //RECORD130 = (this.TotalWidth_Stable / 2).ToString("F2"),
                //RECORD131 = Math.Abs(dataFile.XReference - dataFile.MeasureKeys.FirstOrDefault().Coordinate).ToString("F2"),
                ////右侧宽设定值
                //RECORD132 = (this.TotalWidth_Stable / 2).ToString("F2"),
                //RECORD133 = Math.Abs(dataFile.XReference - dataFile.MeasureKeys.LastOrDefault().Coordinate).ToString("F2"),

                RECORD134 = this.AngleWidth_Stable?.ToString("F2"),
                RECORD135 = this.AngleWidth_Scan?.ToString("F2"),

                RECORD140 = this.TotalThickness_Stable?.ToString("F2"),
                RECORD141 = this.TotalThickness_Scan?.ToString("F2"),
                RECORD143 = this.TotalThickness_Points?.ToString("F2"),
                RECORD144 = this.AngleThickness_Stable?.ToString("F2"),
                RECORD145 = this.AngleThickness_Scan?.ToString("F2"),
                RECORD159 = this.UserId,
                RECORD160 = this.Shift,//班次
                RECORD161 = this.SpecNameInfact,//实际规格
                RECORD162 = this.Remark,//备注
                RECORD163 = this.PassStatus,//判定结果

                //面积比
                //RECORD160 = this.AreaPercent.ToString("F2"),

                //对称性
                //RECORD161 = this.TotalWidth_Symmetry.ToString("F2"),
                //断面形状
                RECORD164 = this.CrossSectionShape,
                EQP = this.Eqp,
            };
            //this.UpdateProcessStep(processStep, dataFile);
            return processStep;
        }

    }
}
